# name : Number of Observations and Variables in a SAS Data Set (Dynamically)
# key : number.of.obs.macro
# contributor: Shuguang Sun
# --
%macro obsnvars(ds);
   %global dset nvars nobs;
   %let dset=&ds;
   %let dsid = %sysfunc(open(&dset));

   %if &dsid %then %do;
      %let nobs =%sysfunc(attrn(&dsid, nlobs));
      %let nvars=%sysfunc(attrn(&dsid, nvars));
      %let rc = %sysfunc(close(&dsid));
   %end;

   %else %put open for data set &dset failed - %sysfunc(sysmsg());
%mend obsnvars;
